<?php

/*
 * This file is part of the yuki package.
 * Copyright (c) 2011 olamedia <olamedia@gmail.com>
 *
 * This source code is release under the MIT License.
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * yPoint - java.awt.Point implementation
 * A point representing a location in (x,y) coordinate space, 
 * specified in integer precision.
 *
 * @package yuki
 * @subpackage geometry
 * @version SVN: $Id: yPoint.php 145 2011-02-20 04:22:41Z olamedia@gmail.com $
 * @revision SVN: $Revision: 145 $
 * @date $Date: 2011-02-20 04:22:41 +0000 (Sun, 20 Feb 2011) $
 * @author olamedia
 * @license http://www.opensource.org/licenses/mit-license.php MIT
 */
class yPoint{
    /**
     *
     * @var type 
     */
    protected $_x = 0;
    protected $_y = 0;
    /**
     * Constructor.
     */
    public function __construct(){
        // Point()
        // Constructs and initializes a point at the origin (0, 0) of the coordinate space.
        // Point(int, int)
        // Constructs and initializes a point at the specified (x, y) location in the coordinate space.
        // Point(Point)
        // Constructs and initializes a point with the same location as the specified Point object.
        $args = func_get_args();
        switch (func_num_args()){
            case 1:
                $arg = func_get_arg(0);
                if ($arg instanceof yPoint){
                    $this->_x = $arg->getX();
                    $this->_y = $arg->getY();
                }
                break;
            case 2:
                $this->_x = $args[0];
                $this->_y = $args[1];
                break;
            default:
                break;
        }
    }
    /**
     * Determines whether or not two points are equal.
     * @param bool $point
     */
    public function equals($point){
        return ($this->_x == $point->getX() && $this->_y == $point->getY());
    }
    /**
     * Sets the location of the point to the specified location.
     * @return yPoint 
     */
    public function setLocation(){
        $args = func_get_args();
        switch (func_num_args()){
            case 1:
                $point = array_shift($args);
                $this->_x = $x->getX();
                $this->_y = $x->getY();
                break;
            case 2:
                $x = array_shift($args);
                $y = array_shift($args);
                $this->_x = $x;
                $this->_y = $y;
                break;
        }
        return $this;
    }
    /**
     * Returns the location of this point.
     * @return yPoint 
     */
    public function getLocation(){
        return $this;
    }
    /**
     * Moves this point to the specified location in the (x, y) coordinate plane.
     * @param int $x
     * @param int $y
     * @return yPoint 
     */
    public function move($x, $y){
        $this->_x = $x;
        $this->_y = $y;
        return $this;
    }
    /**
     * Translates this point, at location (x,y)
     * by dx along the x axis and dy along the y axis 
     * so that it now represents the point (x+dx,y+dy).
     * @param int $dx
     * @param int $dy
     * @return yPoint 
     */
    public function translate($dx, $dy){
        $this->_x += $dx;
        $this->_y += $dy;
        return $this;
    }
    public function setX($x){
        $this->_x = $x;
        return $this;
    }
    public function setY($y){
        $this->_y = $y;
        return $this;
    }
    /**
     * Returns the X coordinate of the point in double precision.
     * @return double 
     */
    public function getX(){
        return (double) $this->_x;
    }
    /**
     * Returns the Y coordinate of the point in double precision.
     * @return double 
     */
    public function getY(){
        return (double) $this->_y;
    }
}

